package com.yindian.cos.easy.security;

import com.yindian.cos.easy.security.authentication.logout.LogoutService;
import com.yindian.cos.easy.security.authentication.token.TokenStore;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;

import javax.servlet.FilterChain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 退出
 *
 * @author zhangchuanhao
 * @create 2018/11/23
 */
@Log4j2
@Component
public class LogoutServiceImpl implements LogoutService {

    @Autowired
    private TokenStore tokenStore;

    @Override
    public void logout(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws IOException {
        String token = request.getHeader("access_token");
        tokenStore.removeToken(token);
        response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
        response.getWriter().print("1");
    }
}
